<template>
  <el-dialog :title='titleFont' :visible.sync='isShow' width='700px' :lock-scroll=false :close-on-click-modal=false @close='clearForm("queryForm")' @open="openInitializtaion">
    <div v-loading="loading">
      <el-card class='type-info-box-card'>
        <el-form ref='queryForm' size='mini' :model="queryForm" label-width="80px" :rules="rules" label-position="left">
          <el-row :gutter="30">
            <el-col :lg='24'>
              <el-form-item label='柜员号' prop='AGENTID'>
                <!-- <el-input v-model='queryForm.AGENTID' disabled></el-input> -->
                <el-select v-model='queryForm.AGENTID' filterable>
                  <el-option v-for='item in AGENTIDS' :key='item.AGENTNAME' :label='item.AGENTNAME' :value='item.AGENTID'>
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <!-- <el-col :md='12' :lg='12'>
                <el-form-item label='柜员姓名' prop='AGENTNAME'>
                  <el-input v-model='queryForm.AGENTNAME' disabled></el-input>
                </el-form-item>
              </el-col> -->
          </el-row>
          <el-row :gutter="30">
            <el-col :lg='24'>
              <el-form-item label='岗位名称' prop='POSTID'>
                <!-- <el-radio-group v-model='queryForm.POSTID' class="modelBox">
                  <el-radio v-for='item in POSTOpions' :key='item.POSTID' :label='item.POSTID'>{{item.POSTNAME}}</el-radio>
                </el-radio-group> -->
                 <el-select v-model='queryForm.POSTID' filterable>
                  <el-option v-for='item in POSTOpions' :key='item.POSTID' :label='item.POSTNAME' :value='item.POSTID'>
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="30">
            <el-col :lg='24'>
              <el-form-item label='可用范围'  prop='HOLIDAY'>
                <el-radio v-model='queryForm.HOLIDAY' label='0'>工作日可用</el-radio>
                <el-radio v-model='queryForm.HOLIDAY' label='1'>节假日可用</el-radio>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <div slot="footer" style="margin:10px 0;text-align:center">
        <el-button size="mini" @click="isShow=false">取消</el-button>
        <el-button type='primary' size='mini' @click="submit">确定</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
  import DateUtils from '@/CTManage/utils/DateUtils';
  import request from "@/common/utils/requestCT";
  import cloudTellerAdd from "@/message/CTManage/teller/cloud-teller-add";
  import selectTree from "@/components/selectTree2/";
  import getGlobalParams from '@/common/utils/getGlobalParams';
  import spinnerList from "@/message/spinnerDataQuery/spinner-data-query";
  import channelNameQuery from "@/message/shared/channel-name-query";
  import tellerPostAdd from "@/message/CTManage/teller-post/teller-post-add";
  import cloudTellerQuery from "@/message/CTManage/teller/cloud-teller-query";
  import queryInfo from "@/message/CTManage/agent-postinfo-manage/agent-postinfo-query";
  export default {
    components: {
      selectTree
    },
    data() {
      return {
        AGENTIDS: [],
        loading: false,
        titleFont: '柜员对应岗位新增',
        queryForm: { //表单数据
          AGENTID: '',
          AGENTNAME: '',
          POSTID: [],
          WORKDAY: '',
          HOLIDAY: ''
        },
        POSTOpions: [
        ],
        rules: { //表单校验规则 
          POSTID: [{
            required: true,
            message: "请选择岗位",
            trigger: "change"
          }],
          AGENTID: [{
            required: true,
            message: "请选择柜员",
            trigger: "change"
          }],
          HOLIDAY: [{
            required: true,
            message: "请选择",
            trigger: "change"
          }]
        }
      };
    },
    props: {
      option: Object
    },
    methods: {
      //查询岗位基本信息
      queryPost() {
            this.currentRowData = '';
            this.loading = true; 
            let resBody = new queryInfo();
            // resBody.data.POSTID = this.queryForm.POSTID;
            // resBody.data.POSTNAME = this.queryForm.POSTNAME;
            // resBody.QueryPageNo = this.currentPage;
            // resBody.QueryRowNum = this.pageSize;
            request(resBody)
                .then(response=>{
                    if (response.SYS_HEAD.ReturnCode == "000000") {
                        this.POSTOpions = response.RSP_BODY.resultSet;
                        // this.total = this.tableData.length;
                    } else {
                        this.$message({
                            type: "error",
                            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
                        });
                    }
                    this.loading = false;
                })
                .catch(error=>{
                    this.$message({
                        type: "warning",
                        message: "页面出错！"
                    });
                    this.loading = false;
                    console.error(error)
                })
        },
      queryTeller() {
        let resBody = new cloudTellerQuery();
        resBody.data.branchNo = this.$store.state.user.branchId;
        request(resBody)
          .then(response => {
            if (response.SYS_HEAD.ReturnCode === "000000") {
              this.loading = false;
              this.AGENTIDS = response.RSP_BODY.resultSet;
            } else {
              this.$message({
                type: "error",
                message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
              });
            }
          })
   
      },
      // 获取渠道名称方法
      async channelNameQuery() {
        this.loading = true;
        this.tableData = [];
        this.tableTotal = 0;
        let resBody = new channelNameQuery();
        let response = await request(resBody);
        this.loading = false;
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.CHLNAMEOpions = response.RSP_BODY.resultSet;
          console.log(response)
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          });
        }
      },
      openInitializtaion() {
        this.queryTeller();
        this.queryPost();
       
        this.titleFont = '柜员对应岗位管理';
     
      },
    
      submit() {
        //添加策略事件
        this.$refs["queryForm"].validate(valid => {
          if (valid) {
            this.loading = true;
            const resBody = new tellerPostAdd();
            const codeStr = this.queryForm.POSTID;
            resBody.data.AGENTID = this.queryForm.AGENTID;
            resBody.data.AGENTNAME = this.queryForm.AGENTNAME;
            resBody.data.MODIFUSER = this.$store.state.user.userNo;
            resBody.data.WORKDAY = this.queryForm.HOLIDAY=='0' ? '1' : '0';
            resBody.data.HOLIDAY = this.queryForm.HOLIDAY=='1' ? '1' : '0';
            resBody.data.POSTID = codeStr;
            request(resBody)
              .then(response => {
                if (response.SYS_HEAD.ReturnCode === "000000") {
                  this.loading = false;
                  this.$message({
                    type: "success",
                    message: "柜员对应岗位新增成功!"
                  });
                  this.isShow = false;
                  this.$emit("refreshTable");
                } else {
                  this.$message({
                    type: "error",
                    message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
                  });
                   this.loading = false;
                }
              })
              .catch(error => {
                this.loading = false;
                console.log(error);
              });
          }
        });
      },
      clearForm(item) {
        if (this.$refs.queryForm) {
          this.$refs.queryForm.resetFields();
          this.$refs.queryForm.clearValidate();
        }
      }
    },
    computed: {
      isShow: {
        get: function() {
          return this.option.isShow;
        },
        set: function(newValue) {
          this.option.isShow = newValue;
        }
      }
    },
    async created() {}
    // mounted() {
    //   window.addEventListener("scroll", this.handleScroll);
    // }
  };
</script>

<style lang="scss" scope>
  .modelBox {
    // height: 160px;
    overflow: auto;
  }
  .el-checkbox {
    // margin: 2px 0px 2px 30px;
    width: 150px;
  }
  .el-checkbox+.el-checkbox {
    margin-left: 0px;
}
  // .modelBox::-webkit-scrollbar {
  //   display: none
  // }
</style>
